<%@ page language="java" contentType="text/html; charset=UTF-8"  pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<%@include file="/header.jsp" %>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>组织页面</title>
<script type="text/javascript">
function refGrid(){
	$('#datagridtable').treegrid("clearChecked");
	$('#datagridtable').treegrid("options").url='${base}sysOrg/orgList?'+$("form").serialize();
	$('#datagridtable').treegrid("load");  
}
   
  $(function(){
	  $("#searchbtn").click(function(){refGrid();});
	  
	  $('#datagridtable').treegrid({    
		    singleSelect:false,
		    collapsible:false,
		    url:'${base}sysOrg/orgList?'+$("form").serialize(),
		    method:'post',
		    pagination:true,
		    toolbar:'#toolbar',
			pageSize:20,
			multiSort:true,
			rownumbers:true,
			border:false,
			animate:true,
			idField:'id',
			autoRowHeight:false,
			treeField:'orgAbbr',
			fitColumns: true,
		    columns:[[    
		        {field:'id',checkbox:true},    
		        {field:'orgAbbr',title:'组织简称',width:100,sortable:true},    
		        {field:'orgName',title:'组织全称',width:150,sortable:true},
		        {field:'orgCode',title:'组织编号',width:100,sortable:true},
		        {field:'orgStatus',title:'状态',width:80,sortable:true,formatter:function(value,row,index){
			        var data=${SysOrgStatus};
			        for(var i=0;i<data.length;i++){
			        	if(data[i].itemValue==value&&data[i].itemValue!='')
				        	return data[i].itemName;  
 				        }
			        }},
		        {field:'orgType',title:'类型',width:80,sortable:true,formatter:function(value,row,index){
			        var data=${SysOrgType};
			        for(var i=0;i<data.length;i++){
			        	if(data[i].itemValue==value&&data[i].itemValue!='')
				        	return data[i].itemName;  
 				        }
			        }},
		        {field:'orderNo',title:'排序',width:50,sortable:true},
		        {field:'remark',title:'描述',width:300,sortable:true}
		    ]]    
		});
	   $("#addBtn").click(function(){
		   var selOpts =$('#datagridtable').treegrid("getChecked");
			if(selOpts.length==0){
				myConfirm("提示信息","未选择父组织时，将添加顶级组织，确定继续吗?",function(r){
                   if(r){
                   myDialog({title:"增加顶级组织",src:"${base}sysOrg/addPage",width:750,height:300,callBack:refGrid}); 
                }
			});
				}
			else if(selOpts.length>1)
			myAlert("错误信息","请选择一个父组织！","e");
			else
			myDialog({title:"增加子组织",src:"${base}sysOrg/addPage?pId="+selOpts[0].id,width:750,height:300,callBack:refGrid});
	      });
	      $("#editBtn").click(function(){
	    	  var selOpts =$('#datagridtable').treegrid("getChecked");
				if(selOpts.length==0||selOpts.length>1)
					myAlert("错误信息","请选择一个组织！","e");
				else
				  myDialog({title:"编辑组织",src:"${base}sysOrg/editPage?id="+selOpts[0].id,width:750,height:300,callBack:refGrid});
	      });
	      $("#delBtn").click(function(){
	    	  var selOpts =$('#datagridtable').treegrid("getChecked");
				var ids=[];
				var flag=true;
				if(selOpts.length>0){
				$.each(selOpts,function(i,v){
				var children=$('#datagridtable').treegrid("getChildren",v.id);
				     ids.push(v.id);
					 if(children&&children.length>0){
						 myAlert("错误信息","存在子组织时不可删除！","e");
						 flag=false;
                        return false;
						 }
				});
				}else{
					myAlert("错误信息","请选择需要删除的组织！","e");
					flag=false;
				}
				if(flag)
				myConfirm("提示信息","确定删除选中的数据吗?",function(r){
                       if(r){
                      	 myAjax({url:"${base}sysOrg/delOrg",data:{"ids":ids},  
                          	 success:function(data){
                                    if(data.error=='0')
                                  	      refGrid();
                                    else
                                  	  myAlert("错误信息",data.msg,"e");   
                          	 }}); 
                    }
				});
	      });
	      $("#detailBtn").click(function(){
	    	  var selOpts =$('#datagridtable').treegrid("getChecked");
				if(selOpts.length==0||selOpts.length>1)
					myAlert("错误信息","请选择一个父组织！","e");
				else
				  myDialog({title:"查看组织",src:"${base}sysOrg/detailPage?id="+selOpts[0].id,width:750,height:300,
					  callBack:function(){
					  $('#datagridtable').treegrid("clearChecked");}});
	      });
});
</script>
</head>
<body>
   <div id="toolbar">
	<div class="toolbar_searchcondition">
   <form class="easyui-form" action="${base}sysOrg/orgList"  method="post">
	  组织名称: <input class="easyui-textbox" name="params['orgName']" type="text"/>&nbsp;
	  组织编号: <input class="easyui-textbox"  name="params['orgCode']" type="text"/>&nbsp;
      类型: 
	  <input class="easyui-combobox" panelHeight="auto" name="params['orgType']" data-options='valueField:"itemValue",textField:"itemName",data:${SysOrgType},editable:false' />&nbsp;
		状态: 
	  <input class="easyui-combobox" panelHeight="auto" name="params['orgStatus']" data-options='valueField:"itemValue",textField:"itemName",data:${SysOrgStatus},editable:false' />
		   <a href="#" class="easyui-linkbutton searchbtn" iconCls="icon-search" id="searchbtn">查询</a>
		</form>
	</div>
	<div class="toolbar_btns">
	    <a href="#" class="easyui-linkbutton" iconCls="icon-add" plain="true" id="addBtn">添加</a>
		<a href="#" class="easyui-linkbutton" iconCls="icon-edit" plain="true" id="editBtn">编辑</a>
		<a href="#" class="easyui-linkbutton" iconCls="icon-remove" plain="true" id="delBtn">删除</a>
		<a href="#" class="easyui-linkbutton" iconCls="icon-search" plain="true" id="detailBtn">查看</a>
	</div>
   </div>
	  <table id="datagridtable"  style="width:1200px;height:500px" fit="true"></table>
</body>
</html>